package com.zuo.newktproject.hilt

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MyViewModel @Inject constructor(
    private val repository: MyRepository
) : ViewModel() {
    private val _uiState = MutableStateFlow("")
    val uiState = _uiState.asStateFlow()

    val liveData = repository.getLiveData()

    fun fetchData() {
        viewModelScope.launch {
            _uiState.value = "Loading..."
            val result = repository.fetchData()
            _uiState.value = result
        }
    }
}
